using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PP.Models;
using System.Diagnostics;
using System.Net.Mail;
using System.Configuration;

namespace PP.Controllers
{   
    public class PatientController : Controller
    {
		// If you are using Dependency Injection, you can delete the following constructor

        public PatientController()
        {
        }

        //
        // GET: /Patient/Create

        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Patient/Create

        [HttpPost]
        public ActionResult Create(Patient patient)
        {
            if (ModelState.IsValid) {

                // email the message here
                string toEmail = ConfigurationManager.AppSettings["EmailAddressForApplications"];

                using (SmtpClient smtp = new SmtpClient())
                {
                    
                    MailMessage msg = new MailMessage();
                    msg.To.Add(toEmail);
                    msg.Subject = "Patient Application";
                    msg.Body = patient.ToString();


                    smtp.Send(msg);
                }

                return RedirectToAction("Index", "Home");
            } else {
				return View();
			}
        }
    }
}

